package com.umeox.watch.audiobooks.db

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.umeox.watch.audiobooks.base.BaseApp

/**
 * Created by Rambo 2021/8/18
 * Describe:
 */
@Database(entities = [AllStory::class, RecommendStory::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {

    abstract fun allStoryDao(): AllStoryDao
    abstract fun recommendStoryDao(): RecommendStoryDao

    companion object {
        private var instance: AppDatabase? = null

        @Synchronized
        fun get(): AppDatabase {
            if (null == instance) instance = Room.databaseBuilder(
                BaseApp.getContext().applicationContext,
                AppDatabase::class.java,
                "iqibla_story"
            ).allowMainThreadQueries().build()
            return instance as AppDatabase
        }
    }
}